package org.cloudnote.controller;

import org.cloudnote.service.NoteService;
import org.cloudnote.util.NoteResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/note")
public class NoteController {

    @Autowired
    private NoteService noteService;


    @RequestMapping("/recycle.do")
    @ResponseBody
    public NoteResult recycleNote(String noteId){
        //去数据库执行 UPDATE cn_note  SET cn_note_status_id=1
        //修改NoteMapper.xml 中 findByBookId：select * from cn_note where cn_notebook_id = #{id} AND cn_note_status_id=1
        System.out.println(noteId);
        return new NoteResult();
    }

    @RequestMapping("/update.do")
    @ResponseBody
    public NoteResult updsateNote(String noteTitle,String noteBody,String noteId){
        NoteResult result = noteService.updateNote(noteTitle,noteBody,noteId);
        return result;
    }
    @RequestMapping("/add.do")
    @ResponseBody
    public NoteResult addNote(String bookId,String userId,String noteTile){
        NoteResult result = noteService.addNote(bookId,userId,noteTile);
        return result;
    }

    @RequestMapping("/load.do")
    @ResponseBody
    public NoteResult loadNoteDetail(String id){
        NoteResult result = noteService.loadNoteDetail(id);
        return result;
    }

    @RequestMapping("/loadnotes.do")
    @ResponseBody
    public NoteResult loadNotes(String bookId){
        NoteResult result = noteService.loadNotes(bookId);
        return result;
    }
}
